import request from '@/config/axios'

export interface EvalTemplateVO {
  id?: number
  templateName: string
  templateCode: string
  methodTypeId?: number
  templateVersion?: string
  templateContent: string
  applicableProfession?: string
  applicableLevel?: string
  applicableIndustry?: string
  templateType?: number
  totalScore?: number
  passScore?: number
  timeLimit?: number
  customFieldsConfig?: string
  templateStatus: number
  isDefault?: boolean
  usageCount?: number
  reviewerId?: number
  reviewTime?: Date
  reviewComments?: string
  createTime?: Date
}

export interface EvalTemplatePageReqVO extends PageParam {
  templateName?: string
  templateCode?: string
  methodTypeId?: number
  templateStatus?: number
  applicableProfession?: string
  isDefault?: boolean
  createTime?: Date[]
}

export interface EvalTemplateSaveReqVO {
  id?: number
  templateName: string
  templateCode: string
  methodTypeId?: number
  templateVersion?: string
  templateContent: string
  applicableProfession?: string
  applicableLevel?: string
  applicableIndustry?: string
  templateType?: number
  totalScore?: number
  passScore?: number
  timeLimit?: number
  customFieldsConfig?: string
  templateStatus?: number
  isDefault?: boolean
  usageCount?: number
}

// 查询评价模板分页
export const getTemplatePage = (params: EvalTemplatePageReqVO) => {
  return request.get({ url: '/eval/template/page', params })
}

// 查询评价模板详情
export const getTemplate = (id: number) => {
  return request.get({ url: '/eval/template/get?id=' + id })
}

// 新增评价模板
export const createTemplate = (data: EvalTemplateSaveReqVO) => {
  return request.post({ url: '/eval/template/create', data })
}

// 修改评价模板
export const updateTemplate = (data: EvalTemplateSaveReqVO) => {
  return request.put({ url: '/eval/template/update', data })
}

// 删除评价模板
export const deleteTemplate = (id: number) => {
  return request.delete({ url: '/eval/template/delete?id=' + id })
}

// 导出评价模板 Excel
export const exportTemplate = (params: EvalTemplatePageReqVO) => {
  return request.download({ url: '/eval/template/export-excel', params })
}

// 启用模板
export const enableTemplate = (id: number) => {
  return request.put({ url: '/eval/template/enable?id=' + id })
}

// 禁用模板
export const disableTemplate = (id: number) => {
  return request.put({ url: '/eval/template/disable?id=' + id })
}

// 设为默认模板
export const setDefaultTemplate = (id: number) => {
  return request.put({ url: '/eval/template/set-default?id=' + id })
}

// 提交审批
export const submitTemplateApproval = (id: number) => {
  return request.put({ url: '/eval/template/submit-approval?id=' + id })
}

// 审批模板
export const approveTemplate = (id: number, approved: boolean, comments?: string) => {
  return request.put({ url: '/eval/template/approve', data: { id, approved, comments } })
}

// 发布模板
export const publishTemplate = (id: number) => {
  return request.put({ url: '/eval/template/publish?id=' + id })
}

// 获取已发布的评价模板列表
export const getPublishedTemplateList = () => {
  return request.get({ url: '/eval/template/list-published' })
}
